﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATM_Client.Properties;

namespace ATM_Client
{
    public partial class Login : Form
    {
        private int loginattemp = 3;
        readonly IATM _client = new ATMClient();
        public Login()
        {
            InitializeComponent();
        }

        private void BtnLoginClick(object sender, EventArgs e)
        {
            string result = _client.Login(txtAccount.Text, txtPIN.Text);
            if (result != null)
            {
                loginattemp++;
                string[] customerInfo = result.Split('&');
                string token = customerInfo[0];
                int errorCode = Convert.ToInt32(customerInfo[1]);
                if (errorCode == 0)
                {
                    MessageBox.Show(Resources.Login_btnLogin_Click_Login_Successfully_);
                    var mainfrom = new MainForm();
                    mainfrom.Show();
                    Hide();
                    MainForm.token = token;
                }
                else
                {
                    if(errorCode==1 && loginattemp>3)
                    {
                        _client.BlockAccount(txtAccount.Text);
                        MessageBox.Show(Resources.Login_BtnLoginClick_You_entered_incorrect_PIN_3_times__Your_account_will_be_blocked_until_you_contact_The_Bank_);
                    }
                    MessageBox.Show(_client.GetError(errorCode));
                }
            }
        }

        private void BtnCancleClick(object sender, EventArgs e)
        {
            Application.Exit();

        }

        private void LoginLoad(object sender, EventArgs e)
        {
           
        }
    }
}
